# -*- coding: utf-8 -*-
import scrapy


class Myt100Spider(scrapy.Spider):
    name = 'myt100'
    allowed_domains = ['maoyan.com']
    start_urls = ['https://maoyan.com/board/4?offset=0']
    page_num = 0

    def parse(self, response):
        dd_list = response.xpath('//*[@id="app"]/div/div/div[1]/dl/dd')
        for dd in dd_list:
            title = dd.xpath('./div/div/div[1]/p[1]/a/text()').get()
            score1 = dd.xpath('./div/div/div[2]/p/i[1]/text()').get()
            score2 = dd.xpath('./div/div/div[2]/p/i[2]/text()').get()
            release_time = dd.xpath('./div/div/div[1]/p[3]/text()').get()
            protagonist = dd.xpath('normalize-space(./div/div/div[1]/p[2]/text())').get()
            score = score1 + score2
            print(title, score, release_time, protagonist)
            move_dict = {
                'title': title,
                'score': score,
                'release_time': release_time,
                'protagonist': protagonist,

            }
            yield move_dict
        self.page_num += 10
        if self.page_num <= 90:
            next_page_url = 'https://maoyan.com/board/4?offset=%s' % self.page_num
            print(next_page_url)
            yield scrapy.Request(url=next_page_url, callback=self.parse)
